tpl1="""
execute as @s at @s {item_if_chain} {if_chain_0}run function {success_func_name}
"""
tpl2="if data block ~ ~ ~ Items[{{Slot:{slot_id}b,id:\"{item_id}\",Count:{item_count}b{item_tags}}}]"

tpl3="if score @s ecb_count{slot_count_id} matches 0"

func_name="advm:recipes/ultimate_core_success"

recipe=[
    {"id":"minecraft:popped_chorus_fruit","count":1,"tags":"{id:\"advm:machines_wire\"}"},{"id":"minecraft:netherite_ingot","count":1,"tags":"{id:\"advm:compacted_ingot\"}"},{"id":"minecraft:popped_chorus_fruit","count":1,"tags":"{id:\"advm:machines_wire\"}"},
    {"id":"minecraft:gray_dye","count":1,"tags":"{id:\"advm:fan\"}"},{"id":"minecraft:shulker_shell","count":1,"tags":"{id:\"advm:unbreaking_mechanic_outershell\"}"},{"id":"minecraft:gray_dye","count":1,"tags":"{id:\"advm:fan\"}"},
    {"id":"minecraft:popped_chorus_fruit","count":1,"tags":"{id:\"advm:machines_wire\"}"},{"id":"minecraft:popped_chorus_fruit","count":1,"tags":"{id:\"advm:machines_battery_box\"}"},{"id":"minecraft:popped_chorus_fruit","count":1,"tags":"{id:\"advm:machines_wire\"}"}
]
tpl2_gen=[]
tpl3_gen=[]
for i,j in enumerate(recipe):
    if j["count"]>0 and j["id"]!= "minecraft:air":
        tags=""
        if j.get("tags",False)!=False:
            tags=",tag:{tags}".format(tags=j["tags"])
        tpl2_gen.append(tpl2.format(slot_id=i,item_id=j["id"],item_count=j["count"],item_tags=tags))
    else:
        tpl3_gen.append(tpl3.format(slot_count_id=i+1))
tpl2_comp=" ".join(tpl2_gen)
tpl3_comp=" ".join(tpl3_gen)
if tpl3_comp:tpl3_comp+=" "
final=tpl1.format(item_if_chain=tpl2_comp,if_chain_0=tpl3_comp,success_func_name=func_name)
with open("recipe_gen.txt","w+") as f:
    f.write(final)